const {MiniAppZipWebpackPlugin, getEntries} = require('@kugou-miniapp/cli-service')
const {prepareUrls} = require('@kugou-miniapp/cli-shared-utils')
const lessVars={
    // 直接覆盖变量
    'tabbar-background-color':
        '#323233',
    'tabbar-item-text-color':
        'white',
    'tabbar-item-active-color':
        'orange',
    'cell-background-color':'#f3f9f1',
    'nav-bar-background-color':'black',
    'nav-bar-title-text-color':'white',
    'nav-bar-icon-color':'white',
    'nav-bar-text-color':'white',
    'cell-group-background-color':'inherit',
    'cell-group-title-color':'black',
    'cell-group-title-font-size':"font-size-lg"
}
module.exports = {
    chainWebpack: config => {
        config
            .externals({
                'mini-app': 'MiniApp'
            })

        if (process.env.VUE_APP_DEVTOOL && process.env.NODE_ENV === 'development') {
            const urls = prepareUrls('http', '0.0.0.0')

            config
                .plugin('define')
                .tap(args => {
                    args[0]['process.env.DEVTOOL_HOST'] = JSON.stringify(urls.lanUrlForConfig)
                    args[0]['process.env.DEVTOOL_PORT'] = JSON.stringify(8098)

                    return args
                })
        }

        if (process.env.NODE_ENV === 'production') {
            config
                .plugin('mini-app-zip')
                .use(MiniAppZipWebpackPlugin, [
                    {
                        r: [
                            {
                                name: "index",
                                content: "all"
                            }
                        ],
                        t: 'dist',
                        d: 'dist'
                    }
                ])
        }
    },
    pages: getEntries(),
    publicPath: './',
    assetsDir:"static",
    css: {
        loaderOptions: {
            sass: {
                prependData: `
        @import "~@/styles/mixins.scss"
        `
            },
            scss: {
                prependData: `
        @import "~@/styles/mixins.scss";
        `
            },
            less: {
                lessOptions: {
                    modifyVars:lessVars
                }
            },
        }
    }
}
